package com.weijin.controller;

import com.weijin.model.entities.Record;
import com.weijin.model.enums.AttendanceStatus;
import com.weijin.model.from.AttendanceFrom;
import com.weijin.model.vo.RestResultVo;
import com.weijin.service.IRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 考勤相关接口
 * 说明：
 * 工作时间： 9:00-18:00 签到时间：9:00之前 签退时间：18:00之后
 *
 * @Author WeiJin
 * @Version 1.0
 * @Date 2025/3/28 9:48
 */
@RestController
@RequestMapping("/record")
@Api(tags = "考勤相关接口")
public class RecordController {

    @Autowired
    private IRecordService recordService;

    /**
     * 签到
     * 签到时间：9:00之前
     *
     * @param attendanceFrom 签到请求信息，包含签到时间，用户id
     * @return 用户签到信息
     */
    @PostMapping("/signIn")
    @ApiOperation("签到")
    public RestResultVo<Record> signIn(@RequestBody AttendanceFrom attendanceFrom) {
        Record record = recordService.signIn(attendanceFrom);
        // 正常打卡响应
        if (AttendanceStatus.NORMAL.equals(record.getStatus())) {
            return RestResultVo.ok(record, "签到成功");
        }
        // 迟到打卡响应
        return RestResultVo.ok(record, "您迟到了哦，下次请早点打卡哦");
    }

    /**
     * 签退
     * 签退时间：18:00之后，
     *
     * @param attendanceFrom 签退请求信息  包含签到时间，用户id
     * @return 签退记录
     */
    @PostMapping("/signOut")
    @ApiOperation("签退")
    public RestResultVo<Record> signOut(@RequestBody AttendanceFrom attendanceFrom) {
        Record record = recordService.signOut(attendanceFrom);
        // 正常签退
        if (AttendanceStatus.NORMAL.equals(record.getStatus())) {
            return RestResultVo.ok(record, "签退成功");
        }
        // 早退
        return RestResultVo.ok(record, "您早退了哦，下次请到下班时间打卡哦");
    }

}
